var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_FrameAnim = /* */function (_cc$Component22) {
  babel_inherits(o, _cc$Component22);
  var _super25 = babel_createSuper(o);
  function o() {
    var _this55;
    babel_classCallCheck(this, o);
    _this55 = _super25.apply(this, arguments);
    _this55.spriteFrames = [];
    _this55.duration = .1;
    _this55.loop = false;
    _this55.playOnload = false;
    _this55.endCallback = null;
    _this55.isPlaying = false;
    _this55.playTime = 0;
    _this55.spriteLen = 0;
    _this55.spriteIndex = 0;
    return _this55;
  }
  babel_createClass(o, [{
    key: "onLoad",
    value: function onLoad() {
      if (!this.sprite) {
        this.sprite = this.node.getComponent(cc.Sprite);
        this.spriteLen = this.spriteFrames.length;
      }
      if (this.sprite) {
        this.sprite.sizeMode = cc.Sprite.SizeMode.RAW;
        this.sprite.trim = false;
        this.playOnload && this.play();
      } else {
        console.error("====[ERR]FrameAnim, 未配置sprite");
      }
    }
  }, {
    key: "setFrames",
    value: function setFrames(e) {
      this.spriteFrames = e;
      this.spriteLen = this.spriteFrames.length;
      this.node.getComponent(cc.Sprite).spriteFrame = e[0];
    }
  }, {
    key: "setLoop",
    value: function setLoop(e) {
      this.loop = e;
      return this;
    }
  }, {
    key: "setEndFn",
    value: function setEndFn(e) {
      this.endCallback = e;
      return this;
    }
  }, {
    key: "play",
    value: function play() {
      if (this.spriteLen <= 0) {
        return console.error("====[ERR]FrameAnim, spriteLen为空"), this;
      } else {
        return this.isPlaying = true, this;
      }
    }
  }, {
    key: "stop",
    value: function stop() {
      this.isPlaying = false;
      return this;
    }
  }, {
    key: "reset",
    value: function reset() {
      this.spriteIndex = 0;
      this.playTime = 0;
      this.sprite.spriteFrame = this.spriteFrames[0];
    }
  }, {
    key: "updateFrame",
    value: function updateFrame(e) {
      if (this.isPlaying && (this.playTime += e, !(this.playTime < this.duration))) {
        this.spriteIndex++;
        this.playTime = 0;
        if (this.spriteIndex >= this.spriteLen) {
          if (!this.loop) {
            this.isPlaying = false;
            return void (this.endCallback && this.endCallback());
          }
          this.spriteIndex = 0;
        }
        this.sprite.spriteFrame = this.spriteFrames[this.spriteIndex];
      }
    }
  }]);
  return o;
}(cc.Component);
cc__decorate([ccp_property({
  type: [cc.SpriteFrame]
})], def_FrameAnim.prototype, "spriteFrames", undefined);
cc__decorate([ccp_property({
  tooltip: "每一帧时长"
})], def_FrameAnim.prototype, "duration", undefined);
cc__decorate([ccp_property()], def_FrameAnim.prototype, "loop", undefined);
cc__decorate([ccp_property()], def_FrameAnim.prototype, "playOnload", undefined);
def_FrameAnim = cc__decorate([ccp_ccclass], def_FrameAnim);
exports.default = def_FrameAnim;